home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 299_01 / error.c < prev    next >
Text File  |  1989-12-28  |  2KB  |  58 lines

  1. /****************************************************************************/
  2. /* file name: error.c                                                       */
  3. /* requires error.h                                                         */
  4. /*  (c) by Ronald Michaels. This program may be freely copied, modified,    */
  5. /*  transmitted, or used for any non-commercial purpose.                    */
  6. /* this file contains the error messages for bp.c                           */
  7. /****************************************************************************/
  8. #include<stdio.h>
  9. #include<stdlib.h>
  10. #include"error.h"
  11.  
  12. #ifdef ECO
  13.      #include<stdlib.h>             /*  required for eco-c compiler  */
  14. #endif
  15.  
  16. char *err_mgs[] = {   /* array of pointers to error messages  */
  17.      "\n\rCANNOT OPEN FILE bp1.dat",
  18.      "\n\rCANNOT OPEN FILE bp2.dat",
  19.      "\n\rCANNOT OPEN FILE bp3.dat",
  20.      "\n\rERROR READING FILE bp1.dat",
  21.      "\n\rERROR READING FILE bp2.dat",
  22.       "\n\rERROR WRITING TO bp3.dat",
  23.      "\n\rINSUFFICIENT MEMORY, alloc FAILURE",
  24.      };
  25.  
  26. /***************************************************************************/
  27. /*  error                                                                  */
  28. /*  function prints error messages and closes program in the event of      */
  29. /*  some malfunction                                                       */
  30. /*  inspired by a function in The C Compendium by Lawrence and England     */
  31. /***************************************************************************/
  32.  
  33. void error(
  34.    int err_no,                    /*  error number  */
  35.    int err_type                   /*  error type  */
  36. )
  37. {
  38.     if(err_no>=0 && err_no<=NO_OF_ERRORS){
  39.       printf("\n\r%s",err_mgs[err_no]);
  40.     }
  41.     else{
  42.         printf("\n\rINVALID ERROR NUMBER");
  43.     }
  44.     if(err_type==FATAL){
  45.         printf("\n\rFATAL ERROR IN PROGRAM, TERMINATING");
  46.         exit(1);
  47.     }
  48.     if(err_type==WARN){
  49.         printf("\n\rWARNING, PRESS ANY KEY TO CONTINUE");
  50.         getch();
  51.     }
  52.     else{
  53.         printf("\n\rINVALID ERROR TYPE, TERMINATING");
  54.         exit(1);
  55.     }
  56. }
  57.  
  58.